package com.nariano.server.domain.utils;

import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

import com.nariano.server.domain.entities.Population;

public class PopulationSet {
    
    Random rand = new Random();
    
    List<Population> population = new LinkedList<Population>();

    public void add(Population p) {
        population.add(p);
    }

    public Collection<Population> getAll() {
        return population;
    }

    public void remove(Population p) {
        boolean removed = population.remove(p);
        if (false==removed) {
            throw new IllegalStateException("Failed to remove: " + p);
        }
    }

    public Population getRandomPopulation() {
        int idx = rand.nextInt(population.size());
        return population.get(idx);
    }
    
}

